﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SchoolLibrary.Entity.Person;
using SchoolLibrary.DataBase.DAO;
using SchoolLibrary.Desktop.Guide.Input;

namespace SchoolLibrary.Desktop.Guide
{
    public class WriterGuideForm : GuideForm<Writer>
    {

        private string[] COLUMN_NAMES = { "id", "Фамилия", "Имя", "Отчество" };

        public WriterGuideForm() : base() { }

        public WriterGuideForm(ViewModeEnum viewMode) : base(viewMode) { }

        protected override string[] getColumnNames()
        {
            return COLUMN_NAMES;
        }

        protected override List<Writer> findAll()
        {
            return WriterDAO.getInstance().findAll();
        }

        protected override Writer findById(long id)
        {
            return WriterDAO.getInstance().findById(id);
        }

        protected override object[] createRow(Writer writer)
        {
            List<object> row = new List<object>();
            row.Add(writer.Id);
            row.Add(writer.Surname);
            row.Add(writer.Name);
            row.Add(writer.MiddleName);
            return row.ToArray();
        }

        protected override void addButton_Click(object sender, EventArgs e)
        {
            WriterInputDialog dialog = new WriterInputDialog();
            dialog.ShowDialog();
            Writer writer = dialog.Writer;
            WriterDAO.getInstance().save(writer);
            this.initData();           
        }

        protected override void editButton_Click(object sender, EventArgs e)
        {
            long id = getSelectedRowId();
            Writer selectedWriter = WriterDAO.getInstance().findById(id);
            WriterInputDialog dialog = new WriterInputDialog(selectedWriter);
            dialog.ShowDialog();
            Writer writer = dialog.Writer;
            WriterDAO.getInstance().save(writer);
            this.initData();
   
        }

        protected override void deleteButton_Click(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }
    }
}
